<?php
class URequest extends Vfriend_Db {	
	var $cache;
	var $clear;
	var $notify;
	public function __construct() {
		$this->notify	= new Notification();
		
		$this->cache 	= new Vfriend_Cache();
		$this->clear 	= $this->cache->clear;
	}	
	public function getUnread($intUserId) {		
		try {				
			$strKey		= REQUEST_GETUNREAD . $intUserId;
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call urequests_get_unread(?)');
				$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, REQUEST_GETUNREAD_EXPIRE);
			}			
			return isset($arrResult[0]['cRead']) ? $arrResult[0]['cRead'] : 0;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::getUnread - ' .$e->getMessage());			
			return null;
		}
	}
	public function get($intUserId, $intRequestId) {
		try {							
			$this->prepare('call urequests_get(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intRequestId, PDO::PARAM_INT, 11);
			$arrResult 	= $this->fetchAll();			
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::get - ' .$e->getMessage());			
			return null;
		}
	}
	public function getAll($intUserId) {
		try {				
			$strKey		= REQUEST_GETALL . $intUserId;
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call urequests_getall(?)');
				$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
				$arrResult 	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, REQUEST_GETALL_EXPIRE);
			}			
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::getAll - ' .$e->getMessage());			
			return null;
		}
	}
	public function addRequest($intUserId, $intRequesterId, $strMessage, $intRefObjId, $intType) {
		try {
			$this->prepare('call urequests_add(?,?,?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intRequesterId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $strMessage, PDO::PARAM_STR);
			$this->bindParam(4, $intRefObjId, PDO::PARAM_INT, 11);
			$this->bindParam(5, $intType, PDO::PARAM_INT, 6);
			if($this->execute()) {
				$this->clear->deleteRequest($intUserId);
			}
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::addRequest - ' .$e->getMessage());			
			return null;
		}
	}
	public function updateRead($intUserId) {		
		try {
			$this->prepare('call urequests_update_read(?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			if($this->execute()) {
				$this->clear->deleteRequest($intUserId);
			}
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::updateRead - ' .$e->getMessage());			
			return null;
		}
	}
	public function deleteRequest($intRequestId,$intUserId,$intRequesterId,$intType) {		
		try {
			$this->prepare('call urequests_delete(?,?,?,?)');
			$this->bindParam(1, $intRequestId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRequesterId, PDO::PARAM_INT, 11);
			$this->bindParam(4, $intType, PDO::PARAM_INT, 4);
			if($this->execute()) {
				$this->clear->deleteRequest($intUserId);
				$this->clear->deleteRequest($intRequesterId);
				$intNtype	= 0;
				if($intType == 3) $intNtype = -15;
				elseif($intType == 4) $intNtype = -16;
				elseif($intType == 5) $intNtype = -17;
				elseif($intType == 6) $intNtype = -18;
				if($intNtype < 0) {
					$strContent = Zend_Json::encode(array('posterid'=>$intUserId));
					$this->notify->insert($intRequesterId,$intNtype,$strContent);
				}
			}
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::deleteRequest - ' .$e->getMessage());			
			return null;
		}
	}
	public function deleteRequestByRefObjId($intRefObjId,$intUserId,$intRequesterId,$intType) {		
		try {
			$this->prepare('call urequests_delete_refobjid(?,?,?,?)');
			$this->bindParam(1, $intRefObjId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRequesterId, PDO::PARAM_INT, 11);
			$this->bindParam(4, $intType, PDO::PARAM_INT, 4);
			if($this->execute()) {
				$this->clear->deleteRequest($intUserId);				
			}
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::deleteRequestByRefObjId - ' .$e->getMessage());			
			return null;
		}
	}
	/** VON */
	public function addGiveVon($intUserId, $intTargetId, $intQuantity) {
		try {
			$this->prepare('call vgives_add(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intQuantity, PDO::PARAM_STR);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$intVgiveId		= isset($arrResult[0]['vgiveid']) ? $arrResult[0]['vgiveid'] : 0;
				if($intVgiveId) {
					$jsonMessage 	= array('quantity'=>$intQuantity);
					$strMessage	 	= Zend_Json::encode($jsonMessage);
					$this->addRequest($intTargetId, $intUserId, $strMessage, $intVgiveId, 2);
					$strContent		= Zend_Json::encode(array('posterid'=>$intUserId,'quantity'=>Vfriend_Function::numberFormat($intQuantity)));
					$this->notify->insert($intTargetId,26,$strContent,$intVgiveId);
				}
				$this->clear->deleteRequest($intTargetId);
				$this->clear->deleteAccount($intUserId, 1);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::addGiveVon - ' .$e->getMessage());			
			return null;
		}
	}
	public function acceptGiveVon($intUserId, $intTargetId, $intRefObjId,&$intPlusVon=0) {
		try {
			$this->prepare('call vgives_accept(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {				
				$this->clear->deleteAccount($intUserId, 1);
				$intPlusVon	= isset($arrResult[0]['von']) ? $arrResult[0]['von'] : 0;
				$strContent		= Zend_Json::encode(array('posterid'=>$intUserId,'quantity'=>Vfriend_Function::numberFormat($intPlusVon)));
				$this->notify->insert($intTargetId,27,$strContent,$intRefObjId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::acceptGiveVon - ' .$e->getMessage());			
			return null;
		}
	}
	public function denyGiveVon($intUserId, $intTargetId, $intRefObjId,&$intPlusVon=0) {
		try {
			$this->prepare('call vgives_deny(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {				
				$this->clear->deleteAccount($intTargetId, 1);
				$intPlusVon	= isset($arrResult[0]['von']) ? $arrResult[0]['von'] : 0;
				$strContent		= Zend_Json::encode(array('posterid'=>$intUserId,'quantity'=>Vfriend_Function::numberFormat($intPlusVon)));
				$this->notify->insert($intTargetId,-27,$strContent,$intRefObjId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::denyGiveVon - ' .$e->getMessage());			
			return null;
		}
	}
	/** BLACKLIST */
	public function addBlacklist($intUserId, $intTargetId) {
		try {
			$this->prepare('call ublacklists_add(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$this->clear->deleteBlacklist($intUserId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::addBlacklist - ' .$e->getMessage());			
			return null;
		}
	}
	public function deleteBlacklists($intUserId, $intTargetId) {
		try {
			$this->prepare('call ublacklists_delete(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$this->clear->deleteBlacklist($intUserId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::addBlacklist - ' .$e->getMessage());			
			return null;
		}
	}
	public function getAllForBlacklist($intUserId, $intOffset, $intLimit, &$intTotal=0) {
		try {
			$strKey 	= '';
			$arrResult 	= null;
			if($intOffset == 0) {
				$strKey 	= REQUEST_GETALLFORBLACKLIST . $intUserId;
				$arrResult	= $this->cache->get($strKey);
			}
			if(!Vfriend_Function::isCached($arrResult)) {
				$this->prepare('call ublacklists_getall(?,?,?)');
				$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
				$this->bindParam(2, $intOffset, PDO::PARAM_INT, 11);
				$this->bindParam(3, $intLimit, PDO::PARAM_INT, 4);
				$arrResult	= $this->fetchAll();
				$this->cache->set($strKey, $arrResult, REQUEST_GETALLFORBLACKLIST_EXPIRE);
			}
			$intTotal	= isset($arrResult[0]['foundRows']) ? $arrResult[0]['foundRows'] : 0;
			return isset($arrResult) ? $arrResult : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::getAllForBlacklist - ' .$e->getMessage());			
			return null;
		}
	}
	/** RELATION */
	public function addRelation($intUserId,$intTargetId,&$intType,&$intRday=0,$intDay=RELATION_TIME) {
		try {
			$this->prepare('call urelations_add(?,?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intType, PDO::PARAM_INT, 4);
			$this->bindParam(4, $intDay, PDO::PARAM_INT, 4);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			$intType	= isset($arrResult[0]['type']) ? $arrResult[0]['type'] : 0;
			$intRday	= isset($arrResult[0]['rday']) ? $arrResult[0]['rday'] : 0;
			if($intError == 0) {			
				$this->clear->deleteRelation($intUserId,$intTargetId);	
				$intNtype 	= 8 + $intType;
				$strContent = Zend_Json::encode(array('posterid'=>$intUserId));
				$this->notify->insert($intTargetId, $intNtype, $strContent);				
			}			
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::addRelation - ' .$e->getMessage());			
			return null;
		}
	}
	public function acceptRelation($intUserId,$intTargetId,$intRefObjId,$intType,$intDay=0,$intMax=0) {
		try {
			$this->prepare('call urelations_accept(?,?,?,?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$this->bindParam(4, $intType, PDO::PARAM_INT, 4);
			$this->bindParam(5, $intDay, PDO::PARAM_INT, 4);
			$this->bindParam(6, $intMax, PDO::PARAM_INT, 6);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {			
				$this->clear->deleteRelation($intUserId,$intTargetId);
				$intNtype	= 0;
				if($intType == 2) $intNtype = 15;
				elseif($intType == 4) $intNtype = 16;
				elseif($intType == 6) $intNtype = 17;
				elseif($intType == 8) $intNtype = 18;
				$strContent = Zend_Json::encode(array('posterid'=>$intUserId));
				$this->notify->insert($intTargetId,$intNtype,$strContent);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::acceptRelation - ' .$e->getMessage());			
			return null;
		}
	}
	public function deleteFriend($intUserId,$intTargetId) {
		try {
			$this->prepare('call urelations_delete(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {			
				$this->clear->deleteRelation($intUserId,$intTargetId);
				$this->clear->deleteRelation($intTargetId,$intUserId);
				$strContent = Zend_Json::encode(array('posterid'=>$intUserId));
				$this->notify->insert($intTargetId,19,$strContent);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::deleteRelation - ' .$e->getMessage());			
			return null;
		}
	}
	public function deleteCloseFriend($intUserId, $intTargetId) {
		try {
			$this->prepare('call urelations_delete_closefriend(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {			
				$this->clear->deleteRelation($intUserId,$intTargetId);
				$this->clear->deleteRelation($intTargetId,$intUserId);
				$strContent = Zend_Json::encode(array('posterid'=>$intUserId));
				$this->notify->insert($intTargetId,20,$strContent);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::deleteCloseFriend - ' .$e->getMessage());			
			return null;
		}
	}
	public function requestDivorce($intUserId, $intTargetId) {
		try {
			$this->prepare('call urelations_request_divorce(?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {	
				$this->clear->deleteRequest($intTargetId);
				$strContent = Zend_Json::encode(array('posterid'=>$intUserId));
				$this->notify->insert($intTargetId,21,$strContent);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::requestDivorce - ' .$e->getMessage());			
			return null;
		}
	}
	/** GIFT */
	public function acceptGift($intUserId, $intTargetId, $intRefObjId, &$intError=0) {
		try {
			$this->prepare('call fortunes_gift_accept(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {				
				$intProductId	= isset($arrResult[0]['productid']) ? $arrResult[0]['productid'] : 0;
				$intProductName	= isset($arrResult[0]['name']) ? $arrResult[0]['name'] : '';
				$intQuantity	= isset($arrResult[0]['quantity']) ? $arrResult[0]['quantity'] : 0;
				$this->clear->deleteFortuneByUser($intUserId, $intProductId);
				$strContent	 	= Zend_Json::encode(array(	'posterid'		=> $intUserId,
															'productid'		=> $intProductId,
															'productname'	=> $intProductName,
															'quantity'		=> Vfriend_Function::numberFormat($intQuantity))
														);
				$this->notify->insert($intTargetId,25,$strContent,$intRefObjId);
			}
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::acceptGift - ' .$e->getMessage());			
			return null;
		}
	}
	public function sellGift($intUserId, $intTargetId, $intRefObjId, &$intError=0) {
		try {
			$this->prepare('call fortunes_gift_sell(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {				
				$intProductId	= isset($arrResult[0]['productid']) ? $arrResult[0]['productid'] : 0;
				$intProductName	= isset($arrResult[0]['name']) ? $arrResult[0]['name'] : '';
				$intQuantity	= isset($arrResult[0]['quantity']) ? $arrResult[0]['quantity'] : 0;
				$this->clear->deleteAccount($intUserId);
				$strContent	 	= Zend_Json::encode(array(	'posterid'		=> $intUserId,
															'productid'		=> $intProductId,
															'productname'	=> $intProductName,
															'quantity'		=> Vfriend_Function::numberFormat($intQuantity))
														);
				$this->notify->insert($intTargetId,25,$strContent,$intRefObjId);
			}
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::sellGift - ' .$e->getMessage());			
			return null;
		}
	}
	public function denyGift($intUserId, $intTargetId, $intRefObjId,&$intError=0) {
		try {
			$this->prepare('call fortunes_gift_deny(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$this->clear->deleteFortuneByUser($intUserId);
				$intProductId	= isset($arrResult[0]['productid']) ? $arrResult[0]['productid'] : 0;
				$intProductName	= isset($arrResult[0]['name']) ? $arrResult[0]['name'] : '';
				$intQuantity	= isset($arrResult[0]['quantity']) ? $arrResult[0]['quantity'] : 0;
				$intPrice		= isset($arrResult[0]['price']) ? $arrResult[0]['price'] : 0;
				$intType		= isset($arrResult[0]['type']) ? $arrResult[0]['type'] : 0;/*0:insert fortune;1:update von*/
				if($intType == 1) {
					$this->clear->deleteAccount($intTargetId);
				}
				$strContent	 	= Zend_Json::encode(array(	'posterid'		=> $intUserId,
															'productid'		=> $intProductId,
															'productname'	=> $intProductName,
															'quantity'		=> Vfriend_Function::numberFormat($intQuantity),
															'price'			=> Vfriend_Function::numberFormat($intPrice),
															'type'			=> $intType
														)
													);
				$this->notify->insert($intTargetId,-25,$strContent,$intRefObjId);
			}
			return isset($arrResult[0]) ? $arrResult[0] : null;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::denyGift - ' .$e->getMessage());			
			return null;
		}
	}
	public function deleteGift($intUserId, $intTargetId, $intRefObjId) {
		try {
			$this->prepare('call fortunes_gift_delete(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$this->clear->deleteFortuneByUser($intUserId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::deleteGift - ' .$e->getMessage());			
			return null;
		}
	}
	/** LIKE */
	public function addGiveLike($intUserId, $intTargetId, $intQuantity) {
		try {
			$this->prepare('call lgives_add(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intQuantity, PDO::PARAM_STR);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {
				$intLgiveId		= isset($arrResult[0]['lgiveid']) ? $arrResult[0]['lgiveid'] : 0;
				if($intLgiveId) {
					$jsonMessage 	= array('quantity'=>$intQuantity);
					$strMessage	 	= Zend_Json::encode($jsonMessage);
					$this->addRequest($intTargetId, $intUserId, $strMessage, $intLgiveId, 7);
					$strContent		= Zend_Json::encode(array('posterid'=>$intUserId,'quantity'=>Vfriend_Function::numberFormat($intQuantity)));
					$this->notify->insert($intTargetId,28,$strContent,$intLgiveId);
				}
				$this->clear->deleteRequest($intTargetId);
				$this->clear->deleteUstat($intUserId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::addGiveLike - ' .$e->getMessage());			
			return null;
		}
	}
	public function acceptGiveLike($intUserId, $intTargetId, $intRefObjId,&$intPlusLike=0) {
		try {
			$this->prepare('call lgives_accept(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {				
				$this->clear->deleteUstat($intUserId);
				$intPlusLike	= isset($arrResult[0]['tlike']) ? $arrResult[0]['tlike'] : 0;
				$strContent		= Zend_Json::encode(array('posterid'=>$intUserId,'quantity'=>Vfriend_Function::numberFormat($intPlusLike)));
				$this->notify->insert($intTargetId,29,$strContent,$intRefObjId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::acceptGiveVon - ' .$e->getMessage());			
			return null;
		}
	}
	public function denyGiveLike($intUserId, $intTargetId, $intRefObjId,&$intPlusLike=0) {
		try {
			$this->prepare('call lgives_deny(?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intTargetId, PDO::PARAM_INT, 11);
			$this->bindParam(3, $intRefObjId, PDO::PARAM_INT, 11);
			$arrResult	= $this->fetchAll();
			$intError	= isset($arrResult[0]['errCode']) ? $arrResult[0]['errCode'] : 0;
			if($intError == 0) {				
				$this->clear->deleteUstat($intTargetId);
				$intPlusLike	= isset($arrResult[0]['tlike']) ? $arrResult[0]['tlike'] : 0;
				$strContent		= Zend_Json::encode(array('posterid'=>$intUserId,'quantity'=>Vfriend_Function::numberFormat($intPlusLike)));
				$this->notify->insert($intTargetId,-29,$strContent,$intRefObjId);
			}
			return $intError;
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::denyGiveLike - ' .$e->getMessage());			
			return null;
		}
	}
	/** REPORT */
	public function addReport($intUserId, $intCate, $intType, $intSrcId, $intOwnerId=0) {
		try {
			$this->prepare('call reports_add(?,?,?,?)');
			$this->bindParam(1, $intUserId, PDO::PARAM_INT, 11);
			$this->bindParam(2, $intCate, PDO::PARAM_INT, 6);
			$this->bindParam(3, $intType, PDO::PARAM_INT, 4);
			$this->bindParam(4, $intSrcId, PDO::PARAM_INT, 11);
			$arrResult = $this->fetchAll();
			if(isset($arrResult[0]['errCode']) && $arrResult[0]['errCode'] == 0)  {
				if($intType == 1) {
					//blogs
					$this->clear->deleteBlogById($intSrcId);
				}elseif($intType == 2) {
					//images
					$this->clear->deleteCmtForPhoto($intSrcId);
				}elseif($intType == 3) {
					//users
					$this->clear->deleteUser($intSrcId);
				}elseif($intType == 4) {
					//news
					$this->clear->deleteNewsById($intSrcId);
				}elseif($intType == 5) {
					//offlines
					$this->clear->deleteOfflineById($intSrcId);
					$this->clear->deleteCmtByOfflineId($intSrcId);
				}elseif($intType == 7) {
					//album
					$objPhoto 	= new Photo();
					$albumInfo 	= $objPhoto->getAlbumInfo($intSrcId);
					$intOwnerId	= isset($albumInfo['userid']) ? $albumInfo['userid'] : 0;
					$this->clear->deleteAlbumByUserId($intOwnerId, $intSrcId);
				}elseif($intType == 8) {
					$this->clear->deleteUblastById($intSrcId);
					//ublast
				}elseif($intType == 9) {
					//places
					$this->clear->deletePlaceById($intSrcId);
				}
			}
		} catch(Exception $e) {
			Vfriend_Function::logDb('URequest::addReport - ' .$e->getMessage());			
			return null;
		}
	}
}
?>